package top.gangster.lunan.userservice.controller;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import top.gangster.lunan.result.Result;
import top.gangster.lunan.userservice.annotation.LoginToken;
import top.gangster.lunan.userservice.annotation.PermissionLimit;
import top.gangster.lunan.userservice.entity.Auth;
import top.gangster.lunan.userservice.mapper.AuthMapper;
import top.gangster.lunan.userservice.service.AuthService;

/**
 * <p>
 * 权限表，权限数字越大权限越高 前端控制器
 * </p>
 *
 * @author vic
 * @since 2021-11-06
 */
@RestController
@RequestMapping("/userservice/auth")
public class AuthController {
  @Resource
  AuthMapper authMapper;
  @Autowired
  AuthService authService;

  /**
   * 列表查看Auth
   * @return Result
   */
  @LoginToken
  @PermissionLimit(role = PermissionLimit.ROLE_STANDARD)
  @GetMapping("/authList")
  public Result getAuthListController(){
    List<Auth> authList = authService.getAuthList();
    if (authList == null){
      return Result.error().message("没查找到任何权限！");
    }
    return Result.ok().data("authList",authList);
  }

  /**
   * 列表查看Auth_level
   * @return Result
   */
  @LoginToken
  @PermissionLimit(role = PermissionLimit.ROLE_STANDARD)
  @GetMapping("/authLevelList")
  public Result getAuthLevelListController(){
    List<Auth> authLevelList = authService.getAuthLevelList();
    if (authLevelList == null){
      return Result.error().message("没查找到任何权限等级！");
    }
    return Result.ok().data("authLevelList",authLevelList);
  }

}

